package com.ruoyi.att.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.att.dto.BsmRegionsListInput;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.att.domain.BsmRegions;
import com.ruoyi.att.service.IBsmRegionsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 区域Controller
 * 
 * @author ruoyi
 * @date 2022-10-25
 */
@RestController
@RequestMapping("/regions")
public class BsmRegionsController extends BaseController
{
    @Autowired
    private IBsmRegionsService bsmRegionsService;

    /**
     * 查询区域列表
     */
    @RequiresPermissions("system:regions:list")
    @GetMapping("/list")
    public TableDataInfo list(BsmRegionsListInput bsmRegions)
    {
        startPage();
        List<BsmRegions> list = bsmRegionsService.selectBsmRegionsList(bsmRegions);
        return getDataTable(list);
    }

    /**
     * 导出区域列表
     */
    @RequiresPermissions("system:regions:export")
    @Log(title = "区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BsmRegionsListInput bsmRegions)
    {
        List<BsmRegions> list = bsmRegionsService.selectBsmRegionsList(bsmRegions);
        ExcelUtil<BsmRegions> util = new ExcelUtil<BsmRegions>(BsmRegions.class);
        util.exportExcel(response, list, "区域数据");
    }

    /**
     * 获取区域详细信息
     */
    @RequiresPermissions("system:regions:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bsmRegionsService.selectBsmRegionsById(id));
    }

    /**
     * 新增区域
     */
    @RequiresPermissions("system:regions:add")
    @Log(title = "区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BsmRegions bsmRegions)
    {
        return toAjax(bsmRegionsService.insertBsmRegions(bsmRegions));
    }

    /**
     * 修改区域
     */
    @RequiresPermissions("system:regions:edit")
    @Log(title = "区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BsmRegions bsmRegions)
    {
        return toAjax(bsmRegionsService.updateBsmRegions(bsmRegions));
    }

    /**
     * 删除区域
     */
    @RequiresPermissions("system:regions:remove")
    @Log(title = "区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bsmRegionsService.deleteBsmRegionsByIds(ids));
    }
}
